#include "widget.h"
#include "ui_widget.h"
#include <QHBoxLayout>
#include "component/switchbutton.h"
#include "component/dialog_popup.h"
#include "subwidget.h"
#include "infosetwidget.h"
#include "seldialog.h"
#include "samptestconfig.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);


    addSwitchButton();
}

Widget::~Widget()
{
    delete ui;
}

//1.测试创建一个子Widget窗口，以模态方式运行
void Widget::on_pushButton_clicked()
{
    subWidget subWgt("subWidget");
    subWgt.exec();
}

//2.测试对话框的公共外框
void Widget::on_pbDialog_clicked()
{
    // 1. 创建外部顶层窗口
    CDialogPopup* pDlg = new CDialogPopup;
    pDlg->SetTitleName(QString::fromUtf8("新增"));

    // 2. 创建窗口，编辑信息
    InfoSetWidget* pWgt = new InfoSetWidget();

    connect(pDlg, &CDialogPopup::sglBtn_Ok, pWgt, &InfoSetWidget::on_pb_clicked_ok);
    connect(pDlg, &CDialogPopup::sglBtn_Cancel, pWgt, &InfoSetWidget::on_pb_clicked_cancel);
    connect(pWgt, &InfoSetWidget::quit, pDlg, &CDialogPopup::close);

    pDlg->AddWidget(pWgt);
    pDlg->exec();

    if (pWgt->IsCancel())
    {
        delete pWgt;
        delete pDlg;
        return;
    }

    // 3. 清指针，销毁对象
    delete pWgt;
    delete pDlg;
}

//3.测试在对话框中，选择下拉框选择下拉项时，对话框窗口是否漂移
void Widget::on_pbSelDlg_clicked()
{
    SelDialog dlg;
    dlg.exec();
}

//4.测试开关切换按钮部件
void Widget::addSwitchButton()
{
    SwitchButton* tSwitchButton = new SwitchButton();
    tSwitchButton->setStyleSheet("QPushButton{background-color: transparent}");
    tSwitchButton->setFixedSize(70,25);

    QHBoxLayout* hLayoutSwitch = new QHBoxLayout(ui->frame);
    hLayoutSwitch->setMargin(0);
    hLayoutSwitch->setSpacing(0);
    hLayoutSwitch->setContentsMargins(10,5,10,5);
    hLayoutSwitch->addWidget(tSwitchButton);
}

//5.测试
void Widget::on_pbShadowWgt_clicked()
{
    SampTestConfig dlg;
    dlg.exec();
}
